HowtoBecomeaProgrammer
About UsContact UsThe input method can be very useful when a program you create needs information from the user. For instance you may need their name and age, or if it is a game, their username. Here's is the syntax for asking for someone's name:
name = input('Please enter your name: ')
print(name)
Let's say that I inputted into the console 'John Smith', without the quotation marks, the code would output 'John Smith', with quotation marks.
If we wanted to be a little more specific about their name, such as that we want to split their name up into first and last name, we could do this:
first_name, last_name = input().split()
We utilize the .split() function that we learned about early in the course, which was utilized to split up the string 'John Smith' so that first_name variable would be equal to 'John' and the last_name variable would be equal to 'Smith'.